package com.ypd.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ypd.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.shop.domain.Statistic;
import com.ypd.shop.service.IStatisticService;
import com.ypd.common.utils.poi.ExcelUtil;
import com.ypd.common.core.page.TableDataInfo;

/**
 * 文章点击量Controller
 * 
 * @author lin
 * @date 2025-01-16
 */

@RestController
@RequestMapping("/shop/statistic")
@Api(tags = "文章点击量Controller")
public class StatisticController extends BaseController
{
    @Autowired
    private IStatisticService statisticService;

    /**
     * 查询文章点击量列表
     */
    @ApiOperation("查询文章点击量列表")
    @PreAuthorize("@ss.hasPermi('shop:statistic:list')")
    @GetMapping("/list")
    public TableDataInfo list(Statistic statistic)
    {
        startPage();
        List<Statistic> list = statisticService.selectStatisticList(statistic);
        return getDataTable(list);
    }

    /**
     * 导出文章点击量列表
     */
    @ApiOperation("导出文章点击量列表")
    @PreAuthorize("@ss.hasPermi('shop:statistic:export')")
    @Log(title = "文章点击量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Statistic statistic)
    {
        List<Statistic> list = statisticService.selectStatisticList(statistic);
        ExcelUtil<Statistic> util = new ExcelUtil<Statistic>(Statistic.class);
        util.exportExcel(response, list, "文章点击量数据");
    }

    /**
     * 获取文章点击量详细信息
     */
    @ApiOperation("获取文章点击量详细信息")
    @PreAuthorize("@ss.hasPermi('shop:statistic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(statisticService.selectStatisticByPropertyId(id));
    }

    /**
     * 新增文章点击量
     */
    @ApiOperation("新增文章点击量")
    @PreAuthorize("@ss.hasPermi('shop:statistic:add')")
    @Log(title = "文章点击量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Statistic statistic)
    {
        return toAjax(statisticService.insertStatistic(statistic));
    }

    /**
     * 修改文章点击量
     */
    @ApiOperation("修改文章点击量")
    @PreAuthorize("@ss.hasPermi('shop:statistic:edit')")
    @Log(title = "文章点击量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Statistic statistic)
    {
        return toAjax(statisticService.updateStatistic(statistic));
    }

    /**
     * 删除文章点击量
     */
    @ApiOperation("删除文章点击量")
    @PreAuthorize("@ss.hasPermi('shop:statistic:remove')")
    @Log(title = "文章点击量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(statisticService.deleteStatisticByIds(ids));
    }
}
